<%--
 *  File:    ERSummary.jsp
 *  @Author: Hilldao
 *  Date:    2001/12/24
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.ERSummary");
  String strModuleName = "ERM";
  String strTableName = "ovorgrelationdetail";
  String privilegeCode = "10301,10307,10308,Z0903";

%>



<%

  //get location
  String strisFollow ="";
  String sourceid ="";
	String IsExternal = "";
	String RelationType = "";
	String RelationType1 = "";
  //get userinfo
  

%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<%@include file="/inc/Print.inc"%>
<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="ersummary"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%
	HashMap orginfo = (HashMap)pageContext.getAttribute("orginfo");
  if(orginfo.get("orgid")!=null)
      sourceid = orginfo.get("orgid").toString().trim();

	 IsExternal = (String)pageContext.getAttribute("IsExternal");

	 if(pageContext.getAttribute("RelationType")!=null)
	   RelationType = (String)pageContext.getAttribute("RelationType");

	 if(pageContext.getAttribute("relationtype1")!=null)
	   RelationType1 = pageContext.getAttribute("relationtype1").toString().trim();

//	 if(RelationType.equals(null))
//	     RelationType.intValue(11);


//	request.getParameter("")
%>
<script>
function poporg()
{
  window.open("../ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>&selectoption=owner&languagecode=<%= strLanguageCode %>", "newwindow", "height=250, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
}
function page_setOrg(id,name,code)
{
  frm.orgid.value = id;
  frm.orgcode.value = code;
  frm.orgname.value = name;
  page_summary("search");
}
<%--self.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";--%>
function clickER(id,follow,reid,sourceid,targetid,defaultgbcode,correspond)
{
  frm.orgrelationdetailid.value = id;
  frm.isFollow.value = follow;
  frm.relationid.value = reid;
  frm.targetorgid.value = targetid;
  frm.sourceorgid.value = sourceid;
  frm.defaultgbcode.value = defaultgbcode;
  frm.correspond.value=correspond;
<%--  self.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";--%>
}
<%if(privilegeSet != null && privilegeSet.contains("1030203")){%>
function page_delete()
{
	  var id = frm.orgrelationdetailid.value;
	  if(id == null || id.length == 0 || id == "" || id == "-1")
	    return;
    if(frm.isFollow.value == 'isFollow')
		{
	    alert("<%= message.getMessageDesc("CAN_NOT_DEL_IT") %>");
			return;
		}
	  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>");
	  if(!flag)
	    return;
	  frm.target = "_self";
	  frm.actionname.value = "delete";
	  isRunning = true;
	  frm.submit();
}
<%}%>
function page_add()
{
    if(frm.relationtype1.value == "")
    {
         alert("<%= message.getMessageDesc("PLEASE_SELECT_RELATIONTYPE") %>");
         return;
    }
    frm.actionname.value = "createnew";
    isRuning = true;
	  frm.submit();
}

function page_summary(actionvalue,orderbyname)
{

  document.frm.value.value = document.frm.relationtype1.value;
  var editform = summaryPrepare(frm,actionvalue,orderbyname);
  editform.action = "ERSummary.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}

function downpage()
{
  var id = frm.orgrelationdetailid.value;
  if(id == null || id.length == 0 || id == "" || id == "-1")
    return;

  var relationid = frm.relationid.value;
  var redetialid = frm.orgrelationdetailid.value;
  var isFollow = frm.isFollow.value;
  var relationtype = frm.defaultgbcode.value;
  var sourceid = frm.sourceorgid.value;
  var targid = frm.targetorgid.value;

  if(frm.isFollow.value != 'isFollow')
    self.location.href = "ERAgreementSummary.jsp?<%= OvalTools.randomURL() %>&ownerorgid=<custom:write name="orginfo" property="orgid"/>&relationdetailid=" + redetialid +"&relationid="+relationid+"&relationtype="+relationtype+"&sourceid="+sourceid+"&targid="+targid+"&languagecode=<%= strLanguageCode %>";
  else
    self.location.href = "ERAgreementSummary.jsp?<%= OvalTools.randomURL() %>&ownerorgid=<custom:write name="orginfo" property="orgid"/>&relationdetailid=" + redetialid +"&relationid="+relationid+"&relationtype="+relationtype+"&sourceid="+sourceid+"&targid="+targid+ "&isfollow=true"+"&languagecode=<%= strLanguageCode %>";
}

function clearpolicypage()
{
  var id = frm.orgrelationdetailid.value;
  if(id == null || id.length == 0 || id == "" || id == "-1")
    return;

  var relationid = frm.relationid.value;
  var redetialid = frm.orgrelationdetailid.value;
  var isFollow = frm.isFollow.value;
  var relationtype = frm.defaultgbcode.value;
  var sourceid = frm.sourceorgid.value;
  var targid = frm.targetorgid.value;

  if(frm.isFollow.value != 'isFollow')
    self.location.href = "ERClearPolicy.jsp?<%= OvalTools.randomURL() %>&ownerorgid=<custom:write name="orginfo" property="orgid"/>&relationdetailid=" + redetialid +"&relationid="+relationid+"&relationtype="+relationtype+"&sourceid="+sourceid+"&targid="+targid+"&languagecode=<%= strLanguageCode %>";
  else
    {
    alert("<%= message.getMessageDesc("ONLY_MAIN_HAVE_CLEARPOLICY") %>");
    return;
   }
}


function page_info()
{
    var relationid = frm.relationid.value;
    var redetialid = frm.orgrelationdetailid.value;

    if(frm.defaultgbcode.value == 1 || frm.defaultgbcode.value == 22)
        frm.actionname.value="info";
    else
        frm.actionname.value="info2";

    isRunning = true;
    frm.submit();
}
function page_print()
{
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_PRINT") %>");
  if(!flag)
    return;
  document.frm.actionname.value = "excelprint"; 
  
  var print_params = new ActiveXObject("Scripting.Dictionary");    
  print_params.add("orgid",document.frm.orgid.value);
  print_params.add("searchname",document.frm.searchname.value);
  print_params.add("searchvalue",document.frm.searchvalue.value);  
  print_params.add("actionname",document.frm.actionname.value);
  print_params.add("pagename",document.frm.pagename.value);
  print_params.add("isexternal",document.frm.IsExternal.value);
  print_params.add("relationtype",document.frm.RelationType.value);
  print_params.add("relationtype1",document.frm.relationtype1.value);
  
  var print_URL = mergeURL('<%=JspHelper.filterNull(realPrintPath)%>',print_params);  
  top.topFrame.PrintController.setCookieId('<%=JspHelper.filterNull( ExcelUtil.GetSessionID(session.getId()))%>');;
  top.topFrame.PrintController.Print(print_URL,"VMITransBalanceReport");  
}

function page_reload()
{
  document.frm.value.value = document.frm.relationtype1.value;
  frm.pageaction.value="OrderBy";
  frm.action = "ERSummary.jsp?<%= OvalTools.randomURL() %>";
  frm.target = "_self";
  isRunning = true;
  frm.submit();  
}
function page_erpartner()
{
	var target = frm.targetorgid.value;
    var source = frm.sourceorgid.value;
	var id = frm.orgrelationdetailid.value;
	var relationid = frm.relationid.value;
	if(frm.defaultgbcode.value == 1 || frm.defaultgbcode.value == 11){
	if(frm.defaultgbcode.value == 1)
	{
       self.location.href = "ERPartner.jsp?<%= OvalTools.randomURL() %>&buyer="+source+"&seller="+target+"&orgid="+"<%=JspHelper.filterNull( sourceid)%>"+"&relationid="+relationid;
	}
   if(frm.defaultgbcode.value == 11)
	{ 
       self.location.href = "ERPartner.jsp?<%= OvalTools.randomURL() %>&buyer="+target+"&seller="+source+"&orgid="+"<%=JspHelper.filterNull( sourceid)%>"+"&relationid="+relationid;
	}
  }
  
   else 
   {
    alert("<%= message.getMessageDesc("MUST_BE_SUPPLIER_OR_CUSTOMER") %>");
    return;
   }

	 }

function page_edit()
{
	  frm.actionname.value = "update";
	  frm.IsEdit.value = "Y";
	  isRuning = true;
	  frm.submit();
}

top.isExternal='<%=JspHelper.filterNull(IsExternal)%>' ;
top.relationType='<%=JspHelper.filterNull(RelationType)%>';
top.relationType1='<%=JspHelper.filterNull(RelationType1)%>';

</script>
<%

  Vector ERSummary = (Vector)pageContext.getAttribute("relationsummary");
  Vector globalpc = (Vector)pageContext.getAttribute("globalpc");
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");

  if(ERSummary == null)
    ERSummary = new Vector();
  cat.debug("The ERSummary is :" + ERSummary);
  if(globalpc == null)
    globalpc = new Vector();

%>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<form name="frm" method="post" action="../../Dispatcher">
		    <input type="hidden" name="pagename" value="ersummary">
		    <input type="hidden" name="actionname">
		    <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">
		    <input type="hidden" name="IsExternal" value="<%=JspHelper.filterNull( IsExternal )%>">
		    <input type="hidden" name="RelationType" value="<%=JspHelper.filterNull( RelationType )%>">
		    <input type="hidden" name="IsEdit">

	  		<input type="hidden" name="value">
  	    <custom:hidden name="orginfo" property="orgid"/>
	      <custom:hidden name="orginfo" property="orgcode"/>
	      <custom:hidden name="orginfo" property="orgname"/>

<table width="100%" cellspacing="0">
  <% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
</table>
  <tr>
      <table width="100%" border="0" cellspacing="0">
        <tr>
          <%if(privilegeSet != null && privilegeSet.contains("1000000")){%>
          <td nowrap><%= label.getLabelName("L_OwnerOrg") + label.getLabelName("L_Colon") %>
            	<input type="text" name="orgname" value="<custom:write name="orginfo" property="orgname"/>" size="30" readonly >
              <a onclick="poporg()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a> &nbsp;
          <td>&nbsp;&nbsp;</td>
          <%}%>
		  <td nowrap><%= label.getLabelName("L_RelationType")+ label.getLabelName("L_Colon")%>

      <%if(RelationType.equals("11")) {%>
      <custom:selectdic property="relationtype1" dictType="GlobalPCCode" valueCriteria="11" disabled="true"/>
      <custom:hidden property="relationtype1" value="11" />
      <%} else if(RelationType.equals("1"))  {%>
      <custom:selectdic property="relationtype1" dictType="GlobalPCCode" valueCriteria="1" disabled="true"/>
      <custom:hidden property="relationtype1" value="1" />
      <%} else {%>
      <custom:selectdic property="relationtype1" dictType="GlobalPCCode" valueCriteria="1-98" defaultValue="----------" defaultValueCost=""  />
      <%}%>

        <td>&nbsp;&nbsp;</td>
          <td>
           <table>
         <%@ include file="/inc/SummarySearch.inc" %>
           </table>
          </td>
         </tr>
       </table>
    </td>
  </tr>
  <tr>
    <td>
      <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellpadding="0" width="100%">


          <tr class="deepblue-left">
            <td width="22" class="title_center" >&nbsp;</td>
            <td width="80" class="title_center" ><a href="javascript:page_summary('orderby','targetorgcode')"><%= label.getLabelName("L_OrgCode") %></a></td>
            <td class="title_center"><a href="javascript:page_summary('orderby','targetorgname')"><%= label.getLabelName("L_OrgName") %></a></td>
            <td width="100" class="title_center"><a href="javascript:page_summary('orderby','targetorgshortname')"><%= label.getLabelName("L_ShortName") %></a></td>
            <td width="80" class="title_center" ><a href="javascript:page_summary('orderby','globalpccode')"><%= label.getLabelName("L_RelationType") %></a></td>
            <td width="60" class="title_center" ><a href="javascript:page_summary('orderby','areaid')"><%= label.getLabelName("L_BusinessArea") %></a></td>
            <td width="100" class="title_center" ><a href="javascript:page_summary('orderby','orggroupid')"><%= label.getLabelName("L_Group") %></a></td>
            <td width="30" class="title_center" ><%= label.getLabelName("L_Property") %></td>
          </tr>
           <%
             int j = 0;
             String strClassType = new String();
             Integer DefaultGBpccode = new Integer(-1);
             Integer nDefaultRelaId = new Integer(-1);
             Integer nDefaultReId = new Integer(-1);
             String  DefaultisFollow = new String();
             Integer DefaultSourceorgid = new Integer(-1);
             Integer DefaultTargetorgid = new Integer(-1);
			 Integer DefaultCorrespond=new Integer(-1);
             boolean bHasChecked = false;
             
             
          %>
          <logic:iterate id="ers" collection="<%= ERSummary %>">
         <%
            HashMap ERMap = (HashMap)pageContext.getAttribute("ers");
            String trgid = "";
            strisFollow = "";
            boolean isFollow = false;

             if(ERMap.get("ownerorgid")!=null);
             {
               trgid = ERMap.get("ownerorgid").toString().trim();
             }
            if(!sourceid.equals(trgid))
            {
               isFollow = true;
               strisFollow = "isFollow";
            }


            String strIsDisabled = new String("");
            String strIsChecked = new String("");

            if(j%2 == 1){
              strClassType = "td-listrom";
            }else{
              strClassType = "";
            }
           if(!bHasChecked)
            {
              strIsChecked = "Checked";
              bHasChecked = true;
              nDefaultRelaId = (Integer)(ERMap.get("orgrelationdetailid"));
              nDefaultReId = (Integer)(ERMap.get("relationid"));
              DefaultisFollow = strisFollow;
              DefaultGBpccode = (Integer)ERMap.get("globalpccode");
              DefaultSourceorgid = (Integer)ERMap.get("sourceorgid");
              DefaultTargetorgid = (Integer)ERMap.get("targetorgid");
			  if(ERMap.get("globalpccode1")!=null)
			  {
				  DefaultCorrespond=(Integer)ERMap.get("globalpccode1");
			  }
            }
            j++;
          %>

          <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'"  onClick="javascript:radiotrue('er<%=JspHelper.filterNull(j)%>');clickER('<%=JspHelper.filterNull( ERMap.get("orgrelationdetailid") )%>','<%=JspHelper.filterNull(strisFollow)%>','<%=JspHelper.filterNull( ERMap.get("relationid") )%>','<%=JspHelper.filterNull( ERMap.get("sourceorgid") )%>','<%=JspHelper.filterNull( ERMap.get("targetorgid") )%>','<%=JspHelper.filterNull( ERMap.get("globalpccode") )%>','<%=JspHelper.filterNull( ERMap.get("globalpccode1") )%>')" class="<%=JspHelper.filterNull(strClassType)%>">

            <td width="5%">
              <input id="er<%=JspHelper.filterNull(j )%>" type="radio" name="checkdept"  value=<%=JspHelper.filterNull( ERMap.get("orgrelationdetailid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked)%> onClick="javascript:clickER('<%=JspHelper.filterNull( ERMap.get("orgrelationdetailid") )%>','<%=JspHelper.filterNull(strisFollow)%>','<%=JspHelper.filterNull( ERMap.get("relationid") )%>','<%=JspHelper.filterNull( ERMap.get("sourceorgid") )%>','<%=JspHelper.filterNull( ERMap.get("targetorgid") )%>','<%=JspHelper.filterNull( ERMap.get("globalpccode") )%>')">
            </td>
            <td>&nbsp;<a href="javascript:page_info()"><%=JspHelper.filterNull( ERMap.get("targetorgcode") )%></a></td>
            <td>&nbsp;<%=JspHelper.filterNull( ERMap.get("targetorgname") )%></td>
            <td>&nbsp;<%=JspHelper.filterNull( ERMap.get("targetorgshortname") )%></td>
            <td>&nbsp;<%=JspHelper.filterNull( ERMap.get("globalpcname") )%></td>
            <td>&nbsp;<%=JspHelper.filterNull( ERMap.get("areaname") )%></td>
            <td>&nbsp;<%=JspHelper.filterNull( ERMap.get("groupname") )%></td>
            <%if(!isFollow){%>
               <td>&nbsp;<%=label.getLabelName("L_Main")%></td>
            <%}else{%>
               <td>&nbsp;<%=label.getLabelName("L_Attached")%></td>
            <%}%>

          </tr>
          </logic:iterate>
          <input type="hidden" name="orgrelationdetailid" value="<%=JspHelper.filterNull( nDefaultRelaId )%>">
          <input type="hidden" name="relationid" value="<%=JspHelper.filterNull( nDefaultReId )%>">
          <input type="hidden" name="isFollow" value="<%=JspHelper.filterNull( DefaultisFollow )%>">
          <input type="hidden" name="defaultgbcode" value="<%=JspHelper.filterNull( DefaultGBpccode )%>">
          <input type="hidden" name="targetorgid" value="<%=JspHelper.filterNull(DefaultTargetorgid)%>">
          <input type="hidden" name="sourceorgid" value="<%=JspHelper.filterNull(DefaultSourceorgid )%>">
		  <input type="hidden" name="correspond" value="<%=JspHelper.filterNull(DefaultCorrespond)%>">

    <% //--------------------------------------  flipping page --%>
    <%@ include file="/inc/SummaryAction.inc" %>



      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td class="summary_top" ></td>
        </tr>
        <tr>
          <td class="td_center">
          <%if (sourceid.equals(CurUserInfo.get("orgid").toString())) { %>
          <a onclick="downpage()"><custom:button type="1" label="L_RelatedConfer" imgsrc="RelatedConfer.gif" border="0" style="width:60"/></a>
          <%}%>


          <a onclick="page_add()"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60"/></a>


          <%
            if(ERSummary.size() > 0){
          %>
          <a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60"/></a>
          <%}%>
<%
  	if(ERSummary.size() > 0 && privilegeSet != null && privilegeSet.contains("1030203"))
  	{
%>
          <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a>
<%
  	}
%>
          <%
            if(ERSummary.size() > 0){
          %>
          <a onclick="page_print()"><custom:button type="1" label="L_Print" imgsrc="print.gif" border="0" style="width:60"/></a>
          <%}%>
		  <a onclick="page_erpartner()"><custom:button type="1" label="L_OrdPartner" imgsrc="OrdPartner.gif" border="0" style="width:60"/></a>
	
          <a onclick="clearpolicypage()"><custom:button type="1" label="L_ClearPolicy" imgsrc="RelatedConfer.gif" border="0" style="width:60"/></a>
        
 
          
          </td>
        </tr>
      </table>
    </td>
  </tr>
   </table>
  </form>
</table>

</body>
</html>


